import {_decorator, Component, Label, resources, Sprite, SpriteFrame, UITransform} from "cc";
import {AssetId} from "db://assets/proto/shared/v1/props";
import {configsHelper} from "db://assets/script/configs-helper";
import {propsConfigsLoader} from "db://assets/script/configs/props-configs-loader";
import {textUtils} from "db://assets/script/utils/text-utils";

const {ccclass, property} = _decorator;

@ccclass('PropItem')
export class PropItem extends Component {

    @property(Sprite)
    propIcon!: Sprite

    @property(Label)
    propNum!: Label

    assetId!: AssetId;

    start() {

    }

    init(assetId: AssetId, num: number) {
        this.assetId = assetId;
        this.propNum.string = textUtils.numberToTenThousand(num, 2)
        const pf = propsConfigsLoader.findPropIcon(assetId)
        if (pf) this.propIcon.spriteFrame = pf!
    }

    initWithDesc(assetId: AssetId, desc: string) {
        this.assetId = assetId;
        this.propNum.string = desc
        const pf = propsConfigsLoader.findPropIcon(assetId)
        if (pf) this.propIcon.spriteFrame = pf!
    }

    changeNum(num: number) {
        this.propNum.string = textUtils.numberToTenThousand(num, 2)
    }


}